// @algorithm @lc id=1000040 lang=cpp 
// @title group-anagrams-lcci


// @test(["eat","tea","tan","ate","nat","bat"])=[["ate","eat","tea"],["nat","tan"],["bat"]]
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> sameDist;
        for(auto & original : strs){
            string ordered(original);
            sort(ordered.begin(), ordered.end());
            sameDist[ordered].push_back(original);
        }
        vector< vector<string> > ans;
        for(auto & dists : sameDist)
            ans.emplace_back(dists.second);
        return ans;
    }
};